const jwt = require('jsonwebtoken');

module.exports = function (req,res,next){
    const token = req.header('x-auth-token');
    if (!token) return res.status(401).send({message:'Access denide. No token provided'});
    try{
        const decoded = jwt.verify(token,'jwtToken');
        req.user = decoded;
        next();
    }catch(ex){
        return res.status(400).send({message:'Invalid token'});
    }
}